Skip to content

fix: serialize undefined array elements as null#1505

Merged
dinwwwh merged 1 commit intomiddleapi:mainfrom
treehill05:fix/serialize-undefined-array-elements-as-null
Mar 26, 2026
Merged

fix: serialize undefined array elements as null#1505
dinwwwh merged 1 commit intomiddleapi:mainfrom
treehill05:fix/serialize-undefined-array-elements-as-null

Conversation

@treehill05
Copy link
Contributor

@treehill05 treehill05 commented Mar 25, 2026

Fixes #1504

Summary by CodeRabbit

  • Bug Fixes
    • Fixed JSON serialization handling of undefined values in arrays to ensure proper round-trip serialization and deserialization.
  • Tests
    • Added comprehensive test coverage for undefined array element handling, including nested cases.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 25, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ae303943-096e-4683-8226-efd3309af565

📥 Commits

Reviewing files that changed from the base of the PR and between 8d90c8f and 3d25f32.

📒 Files selected for processing (2)
  • packages/client/src/adapters/standard/rpc-json-serializer.test.ts
  • packages/client/src/adapters/standard/rpc-json-serializer.ts

📝 Walkthrough

Walkthrough

Fixed a JSON serialization bug where undefined array elements were output as undefined instead of null, breaking SSR hydration. The serializer now outputs null placeholders with metadata for reconstruction during deserialization, ensuring JSON compatibility through all transport layers.

Changes

Cohort / File(s) Summary
Serializer Implementation
packages/client/src/adapters/standard/rpc-json-serializer.ts
Changed array element serialization to return null instead of undefined for undefined values, allowing safe passage through JSON serialization boundaries while metadata preserves the original value for deserialization.
Test Coverage
packages/client/src/adapters/standard/rpc-json-serializer.test.ts
Added test suite validating undefined array element handling, including round-trip serialization/deserialization and nested array scenarios (e.g., TanStack Query pageParams).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

size:S

Poem

🐰 A hop and a fix for arrays so grand,
Where undefined now safely lands—
As null it hides with metadata's care,
JSON highways pass without despair!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the core change: undefined array elements are now serialized as null instead of undefined.
Linked Issues check ✅ Passed The code changes fully address the linked issue #1504 by fixing serialization of undefined array elements to use null placeholders while maintaining meta entries for deserialization recovery.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the undefined array serialization issue; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where undefined elements within arrays were not properly handled during JSON serialization, potentially leading to non-standard JSON output. The changes ensure that such elements are serialized as null for compatibility, while maintaining the original undefined state upon deserialization, thereby improving the robustness and correctness of the RPC JSON serializer.

Highlights

  • Undefined Array Element Serialization: Modified the StandardRPCJsonSerializer to serialize undefined elements within arrays as null to ensure JSON-safe output. Deserialization correctly restores these null values back to undefined.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added bug Something isn't working javascript Pull requests that update javascript code labels Mar 25, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the StandardRPCJsonSerializer to correctly handle undefined values within arrays by serializing them as null for JSON compatibility and using metadata to restore them to undefined upon deserialization. New tests have been added to verify this behavior for both simple and nested arrays. The reviewer suggests adding an additional test case to cover undefined values as object properties, as the current tests focus solely on arrays.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 26, 2026
@codecov
Copy link

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 26, 2026

More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@1505

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1505

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1505

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1505

@orpc/experimental-durable-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-iterator@1505

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@1505

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@1505

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1505

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1505

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1505

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@1505

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@1505

@orpc/experimental-pino

npm i https://pkg.pr.new/@orpc/experimental-pino@1505

@orpc/experimental-publisher

npm i https://pkg.pr.new/@orpc/experimental-publisher@1505

@orpc/experimental-publisher-durable-object

npm i https://pkg.pr.new/@orpc/experimental-publisher-durable-object@1505

@orpc/experimental-ratelimit

npm i https://pkg.pr.new/@orpc/experimental-ratelimit@1505

@orpc/react

npm i https://pkg.pr.new/@orpc/react@1505

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@1505

@orpc/experimental-react-swr

npm i https://pkg.pr.new/@orpc/experimental-react-swr@1505

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1505

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1505

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@1505

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@1505

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@1505

@orpc/standard-server-fastify

npm i https://pkg.pr.new/@orpc/standard-server-fastify@1505

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@1505

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@1505

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@1505

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@1505

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1505

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1505

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1505

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@1505

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@1505

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1505

commit: b216502

@dinwwwh dinwwwh merged commit 89acf15 into middleapi:main Mar 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working javascript Pull requests that update javascript code lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serialize() returns undefined in arrays, breaking SSR hydration after CVE-2026-28794

2 participants